/**
 * 
 */
package com.suyx.job.service.area.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.suyx.job.entity.RoleInfo;
import com.suyx.job.entity.TuInfo;
import com.suyx.job.enums.SectEnums;
import com.suyx.job.utils.ScreenCapture;
import com.suyx.job.utils.SysStaticData;

/**
 * @author syx
 *
 */
@Service
public class GoToHgsAreaServiceImpl extends AbstractAreaService{

	public final static Map<String,String> options_x = new HashMap<>();  
	public final static Map<String,String> options_y = new HashMap<>();
	static {  
		options_x.put("0", "710 330");  
		options_x.put("1", "410 233");  
		options_x.put("2", "510 233");
		options_x.put("3", "610 233"); 
		options_x.put("4", "410 330");
		options_x.put("5", "510 330");
		options_x.put("6", "610 330");
		options_x.put("7", "410 430");
		options_x.put("8", "510 430");
		options_x.put("9", "610 430");
		
		options_y.put("0", "850 325");  
		options_y.put("1", "540 225");  
		options_y.put("2", "640 225");
		options_y.put("3", "740 225"); 
		options_y.put("4", "540 325");
		options_y.put("5", "640 325");
		options_y.put("6", "740 325");
		options_y.put("7", "540 425");
		options_y.put("8", "640 425");
		options_y.put("9", "740 425");
	}
	
	@Override
	public boolean execute(String device, String path, String area) {
		try {
			String[] infos = SysStaticData.AL1.get("花果山").split("&");
			userAL1(device,infos);
			ScreenCapture.mouseClick(device, "1332 139");
			Thread.sleep(2 * 1000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean support(String area) {
		return SectEnums.HGS.getCode().equals(area);
	}

	@Override
	public boolean goToPoint(RoleInfo roleInfo, String path, TuInfo tuInfo) {
		String device = roleInfo.getDevice();
		String area = tuInfo.getZuobiaoX()+" "+tuInfo.getZuobiaoY();
		try {
			Thread.sleep(2 * 1000L);

			ScreenCapture.mouseClick(device, "117 68");//打开地图
	        ScreenCapture.mouseClick(device, "440 120");// 选x坐标
	        String x = area.split(" ")[0];
	        String y = area.split(" ")[1];
	        input_x(device,x);
	        ScreenCapture.mouseClick(device, "710 430");
	        ScreenCapture.mouseClick(device, "560 110"); // 选y坐标
	        input_y(device, y);
	        ScreenCapture.mouseClick(device, "840 425");
	        ScreenCapture.mouseClick(device, "703 112");  // 前往
	        ScreenCapture.mouseClick(device, "1133 82"); //关闭地图
	        
	        startGoto(roleInfo,path,tuInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	private void input_x(String device,String x){
		for(int i =0;i<x.length();i++){
			char c = x.charAt(i);
			String x_zb = options_x.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, x_zb);
		}
	}
	
	private void input_y(String device,String y){
		for(int i =0;i<y.length();i++){
			char c = y.charAt(i);
			String y_zb = options_y.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, y_zb);
		}
	}
}
